package com.kata.chapter15;

import java.util.Iterator;

/**
 * 栈的实现
 * Created by Solidsnake on 2014/12/22.
 */
public class Stack<T>  implements StackIterator<T>{


    private Frame<T> _head;


    public void push(T value) {
        Frame<T> frame = new Frame<T>();
        frame.setValue(value);
        frame.setNext(this._head);

        this._head = frame;
    }

    public T pop() {
        T result = this._head.getValue();
        this._head = this._head.getNext();
        return result;
    }




    @Override
    public boolean hasNext() {

        return null != this._head;
    }

    @Override
    public T next() {
        return this.pop();
    }

    @Override
    public void remove() {

    }

    @Override
    public Iterator iterator() {
        return this;
    }
}
